package com.heima.exam.p2;

import java.util.Collections;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        Person p1 = new Person("xiao1", 18, 150);
        Person p2 = new Person("xiao2", 19, 150);
        Person p3 = new Person("xiao3", 20, 180);
        Person p4 = new Person("xiao4", 20, 190);
        Person p5 = new Person("xiao5", 22, 150);

        TreeSet<Person> tr = new TreeSet<>((a, b) -> {
            if (a.age > b.age) {
                return -1;
            } else if (a.age < b.age) {
                return 1;
            } else {
                return a.weight > b.weight ? 1 : -1;
            }
        });

        Collections.addAll(tr, p1, p2, p3, p4, p5);
        for (Person person : tr) {
            System.out.println(person);
        }
    }
}
